package net.begincode.common.exception;
/**
 * 统一异常
 * */
public class StatusException extends RuntimeException {
    private final Status statusCode;

    public StatusException(Status statusCode) {
        super(notNull(statusCode));
        this.statusCode = statusCode;
    }

    public StatusException(String message, Status statusCode) {
        super(message + " " + notNull(statusCode));
        this.statusCode = statusCode;
    }

    public StatusException(String message, Throwable cause, Status statusCode) {
        super(message + " " + notNull(statusCode), cause);
        this.statusCode = statusCode;
    }

    public StatusException(Throwable cause, Status statusCode) {
        super(cause.getMessage() + " " + notNull(statusCode), cause);
        this.statusCode = statusCode;
    }

    private static String notNull(Status statusCode) {
        if (statusCode == null) {
            throw new IllegalArgumentException("statusCode must not be null");
        }
        return statusCode.toString();
    }

    public Status getStatusCode() {
        return statusCode;
    }
}
